<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Maitai data
 *
 * Get subscriber account details
 *
 * @package     CodeIgniter
 * @subpackage  Libraries
 * @category    Accounts
 * @author      Ian Odiaman | Fluxion, Inc
 * @link
 */
class Maitaidata {

    public $ssb,    $pk,     $proxy;
    function __construct()
    {	
     	$this->prepService();
    }
    
    public function prepService()
    {
		$this->CI =& get_instance();
		 
		require_once $this->CI->config->item('hessian_options');
    	require_once $this->CI->config->item('hessian_client');		

		$CERT_PATH = $this->CI->config->item('certpath');		  
		$this->pk = openssl_pkey_get_private($this->CI->config->item('hessian_keys')); /*. . [1]get the private key for encryption. .*/
	 
		// API URL  
		$url = $this->CI->config->item('service_url_dev');
		
		// Create Hessian call
		$opts = new HessianOptions();  /*. . . [2]configure option object . . .*/
		$opts->typeMap['SharedSecret'] = $this->CI->config->item('com_library'); //this is the java class path of sharedsecret
		$opts->typeMap['Subscriber'] = $this->CI->config->item('com_library_subscriber'); //this is the java class path of sharedsecret
		 
		$opts->version = 1;
		$opts->saveRaw=true;
		$opts->transport = "curl";
		$opts->transportOptions = array(
			CURLOPT_SSL_VERIFYHOST => 2,
			CURLOPT_SSL_VERIFYPEER => FALSE,
			CURLOPT_CAINFO => $CERT_PATH );
        if(0){
		$this->proxy = new HessianClient($url, $opts);	/*. . . [3]use proxy object to connect to hessian services . . . */			
		$sharedSecret = "";  
		openssl_private_encrypt(  $this->CI->config->item('secret_phrase'), $sharedSecret, $this->pk ); /* . . .[4]encrypt the private key. . .*/
		$sharedSecret = base64_encode($sharedSecret); 
		$s = new SharedSecret(); 
		/*. . [5] preparng Sharedsecret / ssb params . . */
	 	$s->sharedSecret = "$sharedSecret"; 
		$s->keyPrefix = "vendor";
		$s->plaintext = "";
		/* . . . . $this->ssb is now prepared . . . . */
		$this->ssb = new SharedSecret() ; 
		$this->ssb = $s;	
		}
    } // end shared key

  public function getGadgetList($Name,$Brand,$minPrice,$maxPrice){   
  	$result = $this->proxy->getGadgetList($this->ssb, $Name, $Brand, $minPrice, $maxPrice);
	return $result;
  }

  public function getStoreList($StoreName, $StoreAddress, $StoreArea){  
	$result = $this->proxy->getStoreList($this->ssb, $StoreName, $StoreAddress, $StoreArea);
	return $result;
  }
 
  public function getPromoTypeList($Name){ 
    $result = $this->proxy->getPromoTypeList($this->ssb, $Name);
	return $result;
  }
  public function getPromoValidityList($promoTypeId){  
	$result =$this->proxy->getPromoValidityList($this->ssb, $promoTypeId);
	return $result;
  }

  public function getPromoList($promoTypeId, $promoTypeName, $validity){
  	// parameter: validity should be object ?  
	$result = $this->proxy->getPromoList($this->ssb, $promoTypeId, $promoTypeName, $validity);
	return $result;
  }

  public function getCommitmentPeriod($promoId,$gadgetPlanPrice){
	$result = $this->proxy->getCommitmentPeriod($this->ssb,$promoId,$gadgetPlanPrice );
	return $result;
  }

  public function checkMsisdn($msisdn){  	  	
	$result = $this->proxy->checkMsisdn($this->ssb, $msisdn);
	return $result;
  }
  
  //public function registerSubscriber($subscriber){   	
  public function registerSubscriber($fName, $mName, $lName, $email, $msisdn, $birthdate, $streetNum, $area, $town, $province, $postalCode, $gadgetId, $promoId, $commitmentPeriod, $storeId, $channelId, $nName)
  {
		$subsObj = new Subscriber();
		$subsObj->fName = $fName;
		$subsObj->mName = $mName;
		$subsObj->lName = $lName;
		$subsObj->email = $email;
		$subsObj->msisdn = $msisdn;
		$subsObj->birthdate = $birthdate;
		$subsObj->streetNum = $streetNum;
		$subsObj->area = $area;
		$subsObj->town = $town;
		$subsObj->province = $province;
		$subsObj->postalCode = $postalCode;
		$subsObj->gadgetId = $gadgetId;
		$subsObj->promoId = $promoId;
		$subsObj->commitmentPeriod = $commitmentPeriod;
		$subsObj->storeId = $storeId;
		$subsObj->channelId = $channelId;
		$subsObj->nickName = $nName;
  
	  $result = $this->proxy->registerSubscriber($this->ssb, $subsObj);
	  return $result;
  }
  
  public function getSubscriptionDetails($planCode){ 
	$result = $this->proxy->getSubscriptionDetails($this->ssb, $planCode);
	return $result;
  } 
	
}

class SharedSecret{
    public $keyPrefix,
           $sharedSecret,
	   	   $plaintext;
}
	
class Subscriber {
	var $fName;
	var $mName;
	var $lName;
	var $email;
	var $msisdn;
	var $birthdate;
	var $streetNum;
	var $area;
	var $town;
	var $province;
	var $postalCode;
	var $gadgetId;
	var $promoId;
	var $commitmentPeriod;
	var $storeId;
	var $channelId;
}

/* End of file Antispamlib.php */
/* Location: ./application/libraries/Antispamlib.php */
